<template>
	<Layout :class="'bg-white p-2'">
	
		<div>
			<Button id="add" type="primary" shape="circle" @click="newUser" >新增用户</Button>
		</div>
		<Layout :class="'bg-white'">
			<Table border :class="'m-1'" :columns="tableInfo.columnInfo" :data="tableInfo.data">
				<template slot-scope="{ row, index }" slot="action">
					<Button type="primary" size="small" style="margin-right: 5px" @click="xiangxi(row.clientId)">详细</Button>
					<Button type="error" size="small" @click="remove(row.clientId)">删除</Button>
				</template>
			</Table>
			<Page :class="'m-2 text-right'" :page-size="tableInfo.pageSize" @on-change="pageSearch" :total="tableInfo.total" />
		</Layout>
	</Layout>
</template>
<script>
	export default {
		data() {
			return {
				searchKey: "",
				searchTel: "",
				searchSec: "",
				tableInfo: {
					currentPage: 1,
					total: 0,
					columnInfo: [
						{
							title: "用户编号",
							key: "clientId",
							width: 70
						},
						{
							title: "账号",
							key: "account",
							width: 200
						},
						{
							title: "用户姓名",
							key: "personName",
							width: 150
						},
						{
							title: "电话",
							key: "phone",
							width: 200
						},
						
						{
							title: "身份证",
							key: "identityCard",
							width: 200
						},
						
						{
							title: "操作",
							slot: 'action'
						}
					],
					data: []
				}
			}
		},
		methods: {
			init: function() {
				this.$data.tableInfo.currentPage = 1;
				this.search();
			},
			newUser: function() {
				this.$router.push({
					name: "order_new"
				});
			},
			xiangxi: function(clientId){
				this.$router.push({
					name:"order_userinfo",
					params:{
						clientId
					}
				});
			},
			
			update(userId){
				this.$router.push({
					name: "user_update",
					params: {
						userId
					}
				});
			},
			remove: function(clientId) {
				
				this.message.confirm({
					title: "删除提示",
					content: "即将删除用户，确定吗？",
					onOk: () => {
						this.http.delete({
							url: "/client/info",
							param: {
								clientId
							}
						}).then(data => {
							
							this.search();
						});
					},
					onCancel: () => {
						this.message.info('操作已取消');
					}
				});
			},
			search: function() {
				this.http.get({
					url: "/client/page",
					param: {
						currentPage: this.$data.tableInfo.currentPage,
	
					}
				}).then(data => {
					this.$data.tableInfo.currentPage = data.current;
					this.$data.tableInfo.total = data.total;
					this.$data.tableInfo.pageSize = data.size;
					this.$data.tableInfo.data = data.records;
				});
			},
			pageSearch: function(changedPage) {
				this.$data.tableInfo.currentPage = changedPage;
				this.search();
			}
		},
		created: function() {
			this.init();
		}
	}
</script>

<style>
	#add{
		float: left;
	}
	
</style>
